<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item
        label="页面名称"
        prop="menu"
        v-hasPermi="['business:hairTeacherSubscribe:queryShopName']"
      >
        <el-input
          v-model="queryParams.menu"
          placeholder="请输入页面名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="页面路由"
        prop="router"
        v-hasPermi="['business:hairTeacherSubscribe:queryShopName']"
      >
        <el-input
          v-model="queryParams.router"
          placeholder="请输入页面路由"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <!-- <el-form-item label="日期" prop="valueDate">
        <el-date-picker
          clearable
          v-model="queryParams.valueDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择预约日期"
          style="width: 150px"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          @click="updatePageName"
        >批量修改页面名称
        </el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="userBehaviorList"
      @selection-change="handleSelectionChange"
      border
    >
      <!-- <el-table-column label="日期" align="center" prop="valueDate" /> -->
      <el-table-column label="页面名称" align="center" prop="menu" />
      <el-table-column label="页面路由" align="center" prop="router" />
      <el-table-column label="访问时长" align="center" prop="sumStayTime">
        <template #default="scope">
          {{ parseConvertTime(scope.row.sumStayTime) }}
        </template>
      </el-table-column>
      <el-table-column label="访问次数" align="center" prop="lockNum" />
      <el-table-column label="访问人数" align="center" prop="peopleNum" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="批量修改页面名称" v-model="pageOpen" width="800px" append-to-body>
      <el-form ref="hairFixTeacherPhotoRef" :model="form" label-width="80px">
        <el-form-item label="修改前">
          <el-input v-model="form.beforeName" placeholder="请输入页面名称" />
        </el-form-item>
        <el-form-item label="修改后">
          <el-input v-model="form.afterName" placeholder="请输入页面名称" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitUpdatePage">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="HairFixShop">
import {batchUpdatePageName, pageBehaviorListApi} from "@/api/business/userBehavior";
import { parseConvertTime } from "@/utils/ruoyi";
import ImageUploads from "@/components/ImageUploads/index.vue";

const { proxy } = getCurrentInstance();
const buttonLoading = ref(false);
const userBehaviorList = ref([]);
const matterButtonList = ref([]);
const openButtonData = ref(false);
const pageOpen = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    menu: undefined,
    router: undefined,
    valueDate: proxy.parseTime(new Date(), "{y}-{m}-{d}"),
  },
});

const { queryParams, form } = toRefs(data);

/** 查询用户访问数据列表 */
function getList() {
  loading.value = true;
  pageBehaviorListApi(queryParams.value).then((response) => {
    userBehaviorList.value = response.rows;
    total.value = response.total;
    loading.value = false;
    console.log("门店预约列表", response);
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
// 取消按钮
function cancel() {
  pageOpen.value = false;
  reset();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value.valueDate = null;
  queryParams.value.menu = null;

  queryParams.value.router = null;

  handleQuery();
}

function updatePageName(){
  pageOpen.value = true;
}

function submitUpdatePage(){
  batchUpdatePageName(form.value).then(response => {
    proxy.$modal.msgSuccess("修改成功");
    pageOpen.value = false;
    form.value = {}
    getList();
  }).finally(() => {
    buttonLoading.value = false;
  });
}

// 点击查看按钮详情
function handleDetials(row) {
  loading.value = true;
  let query = {
    userId: row.userId,
    valueDate: row.valueDate,
  };
  userBehaviorListDetialsApi(query).then((response) => {
    openButtonData.value = true;
    console.log(response.rows);
    matterButtonList.value = response.rows;
    loading.value = false;
  });
}

getList();
</script>
<style>
.info-content {
  border: 2rpx solid #000000;
  padding: 10rpx;
}
</style>
